<script setup>
import { onMounted, ref, defineProps, reactive } from 'vue'
import { getArticleById } from '../../request/api/article';
const props = defineProps({
    articleId: {
        type: Number,
        default: ''
    }
})
const flag = ref(false)
let data = reactive({
    tag: '前端',
    title: '默认标题',
    describe: '默认描述',
    time: '2022.09.10',
    views: '2024',
    url: '/images/63842418879513.png'
})
const getArticle = async () => {
    await getArticleById(props.articleId).then(res => {
        let result = res.data.data
        data.title = result.title
        data.describe = result.describe
        data.url = result.articleImg
        data.views = result.views?result.views:'1024'
        flag.value = true
    })
}

onMounted(() => {
    getArticle()

})

</script>

<template>
    <div class="card" v-if="flag"  @click="$router.push('/articleDetail/' + props.articleId)">
        <div class="card-top">
            <img :src="data.url" alt="task">
            <div class="cover">
                <span>{{ data.tag }}</span>
                <h2>{{ data.title }}</h2>
            </div>
            <p>{{ data.describe }}</p>
        </div>
        <div class="card-bootom">
            <div class="c-b-left">
                <li>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-shijian2"></use>
                    </svg>
                   <span> {{ data.time ? data.time : "2024-01-01" }}</span>
                </li>
                <li>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-yanjing"></use>
                    </svg>
                    <span>
                    {{ (data.views ? data.views : '10086' )}}
                    </span>
                </li>
                <li>
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-good"></use>
                    </svg>
                    <span>
                    {{ data.likes ? data.likes : '23' }}
                    </span>
                </li>
            </div>
            <div>
                <span style="cursor: pointer;" @click="$router.push('/articleDetail/' + props.articleId)">点击阅读</span>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
@keyframes change {
    0% {
        transform: translate(0, -100px) scale(1.05);
    }

    50% {
        transform: translate(0px, -50px) scale(1.02);
    }

    100% {
        transform: translate(0px) (1);
    }
}

.card {
    position: relative;
    min-width: 400px;
    min-height: 200px;
    width: 720px;
    background-color: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
    margin: 0 auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    animation: change .5s linear;

    .card-top {
        position: relative;
        border-radius: 10px 10px 0 0;
        width: 100%;
        height: 360px;

        img {
            border-radius: 10px 10px 0 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .cover {
            position: absolute;
            top: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 100%;
            height: 100%;
            border-radius: 10px 10px 0 0;
            color: #fff;
            transition: all 0.5s linear;
        }

        p {
            position: absolute;
            top: 0;
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            backdrop-filter: blur(5px);
            font-size: 16px;
            margin: 0;
            padding: 0 20px;
            transition: all 0.5s linear;
            opacity: 0;
        }

        span {
            font-size: 14px;
            background-color: #FF2E63;
            padding: 4px 6px;
            line-height: 14px;
            text-align: center;
            border-radius: 4px;
        }

        h2 {
            font-size: 30px;
            font-weight: 400;
            margin: 10px 0;
        }
    }

    .card-bootom {
        position: absolute;
        background-color: #fff;
        overflow: hidden;
        bottom: 0;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        box-sizing: border-box;
        padding: 0 10px;
        height: 40px;
        font-size: 14px;
        line-height: 14px;
        color: #666;
        li {
            margin-right: 10px;
            display: inline-block;
            .icon {
                width: 16px;
                height: 16px;
                vertical-align: -0.15em;
                fill: #666;
                overflow: hidden;
            }

            span {
                line-height: 16px;
                font-size: 14px;
                margin-left: 5px;
            }
        }
        
    }
}

.card:hover {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}


.card-top:hover p {
    opacity: 1;
    transform: scale(1.02);
    transition: all 0.5s linear;
}

.card-top:hover img {
    transform: scale(1.02);
    transition: all 0.5s linear;
}

.card-top:hover .cover span {
    transform: translate(0, -100px);
    transition: all 0.5s linear;
    opacity: 0;
}

.card-top:hover .cover h2 {
    transform: translate(0, 100px);
    transition: all 0.5s linear;
    opacity: 0;
}
</style>